package DAy32;

import java.util.Scanner;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-11-01
 * Time: 16:47
 * To BE A Better Person-2020-3-2
 */
public class TestDemo {
    private static boolean isLeapYear(int y){
        return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
    }
    private static int dayOfmonth(int y,int m){

        if(m==2){
            if(isLeapYear(y)){
                return 29;
            }else {
                return 28;
            }
        }else{
            switch (m){
                case 1:
                    return 31;
                case 3:
                    return 31;
                case 4:
                    return 30;
                case 5:
                    return 31;
                case 6:
                    return 30;
                case 7:
                    return 31;
                case 8:
                    return 31;
                case 9:
                    return 30;
                case 10:
                    return 31;
                case 11:
                    return 30;
                case 12:
                    return 31;
            }
        }
        return 0;
    }
    private static boolean isPrime(int m){
        //处理之前跨年导致的月份的问题

        if(m==1) return false;
        if(m==2) return true;
        boolean ret=false;
        for (int i = 2; i < m; i++) {

            if(m%i==0){
                return true;
            }
            if(i==m-1){
                return false;
            }
        }
        return true;

    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()){
            int sum=0;
            int y1=sc.nextInt();
            int m1=sc.nextInt();
            int d1=sc.nextInt();
            int y2=sc.nextInt();
            int m2=sc.nextInt();
            int d2=sc.nextInt();
            //间隔没有一个月
            if(m1==m2){
                if(isPrime(m1)){
                    for (int i = d1; i <= d2; i++) {
                        sum+=1;
                    }
                }else{
                    for (int i = d1; i <= d2; i++) {
                        sum+=2;
                    }
                }
                System.out.println(sum);
                continue;

            }
            //判断是否跨年
            if(y2>y1){
                m2+=(y2-y1)*12;
            }
            //开始算钱
            for (int i = m1; i < m2; i++) {
                int curY=y1;
                int tempM=i;
                if(i > 12){
                    curY=y2;
                    tempM=(y2-y1)*12;
                }
                if(isPrime(i)){
                    //是素数月
                    for (int j = d1; j < dayOfmonth(curY,tempM); j++) {
                        sum+=1;
                    }
                }else{
                    //不是素数月
                    for (int j = d1; j < dayOfmonth(curY,tempM); j++) {
                        sum+=2;
                    }
                }
            }
            //计算m2月的钱
            if(m2 > 12){
                m2-=(y2-y1)*12;
            }
            if(isPrime(m2)){
                //是素数月
                for (int j = d1; j < d2; j++) {
                    sum+=1;
                }
            }else{
                //不是素数月
                for (int j = d1; j < d2 ;j++) {
                    sum+=2;
                }
            }
            System.out.println(sum);
        }

    }
}
